package com.googlecode.iiddefecttracker.mvcdsl;

import java.util.List;
import java.util.Map;

import org.springframework.web.servlet.ModelAndView;

import com.googlecode.iiddefecttracker.domain.Defect;
import com.googlecode.iiddefecttracker.domain.Project;

/**
 * I am a convenience class contain static methods to be used within tests to
 * help keep test code clear.
 */
public class SpringMVCHelpers {
    
    @SuppressWarnings("unchecked")
    public static Defect defectToViewOf(final ModelAndView modelAndView) {
        
        final Map<String, Object> modelMap = (Map) modelAndView.getModel().get(
                "model");
        
        return (Defect) modelMap.get("defectToView");
    }
    
    @SuppressWarnings("unchecked")
    public static List<Project> projectsOf(final ModelAndView modelAndView) {
        final Map<String, Object> modelMap = (Map) modelAndView.getModel().get(
                "model");
        
        return (List<Project>) modelMap.get("projects");
    }
}
